﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.ComponentModel.DataAnnotations;
using MobileSales.Model.Util;
using MobileSales.Model.Localization;

namespace MobileSales.Model.Employees
{
    [DataContract]
    public class Employee : Params.ParamObject
    {
        #region Public members
        [DataMember]
        public int Id { get; set; }
        [DataMember]
        [Display(Name = "Contract", ResourceType = typeof(ModelStrings))]
        public Contract Contract { get; set; }
        [DataMember]
        [Display(Name = "Role", ResourceType = typeof(ModelStrings))]
        public Role Role { get; set; }
        [DataMember]
        [DataType(DataType.EmailAddress, ErrorMessageResourceName = "InvalidEmail", ErrorMessageResourceType = typeof(ValidationStrings))]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        [Display(Name = "Email", ResourceType = typeof(ModelStrings))]
        public string Email { get; set; }
        [DataMember]
        [Display(Name = "Supervisor", ResourceType = typeof(ModelStrings))]
        public int? SupervisorId { get; set; }
        [DataMember]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        [Display(Name = "Firstname", ResourceType = typeof(ModelStrings))]
        public string Firstname { get; set; }
        [DataMember]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        [Display(Name = "Lastname", ResourceType = typeof(ModelStrings))]
        public string Lastname { get; set; }
        [DataMember]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        [DataType(DataType.Password)]
        [Display(Name = "Password", ResourceType = typeof(ModelStrings))]
        public string Password { get; set; }
        [DataMember]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        [Display(Name = "Zipcode", ResourceType = typeof(ModelStrings))]
        public string Zipcode { get; set; }
        [DataMember]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        [Display(Name = "City", ResourceType = typeof(ModelStrings))]
        public string City { get; set; }
        [DataMember]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        [Display(Name = "Street", ResourceType = typeof(ModelStrings))]
        public string Street { get; set; }
        [DataMember]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        [Display(Name = "Phone", ResourceType = typeof(ModelStrings))]
        public string Phone { get; set; }
        [DataMember]
        [Display(Name = "LocationLongitude", ResourceType = typeof(ModelStrings))]
        public double? LocationLongitude { get; set; }
        [DataMember]
        [Display(Name = "LocationLatitude", ResourceType = typeof(ModelStrings))]
        public double? LocationLatitude { get; set; }
        [DataMember(Name="LocationTimestamp")]
        private string _locationTimestamp { get; set; }
        [Display(Name = "LocationTimestamp", ResourceType = typeof(ModelStrings))]
        public DateTime? LocationTimestamp
        {
            get
            {
                if (_locationTimestamp != null) return DateUtil.Deserialize(_locationTimestamp);
                return null;
            }
            set
            {
                if (value.HasValue) _locationTimestamp = DateUtil.Serialize(value.Value);
                else _locationTimestamp = null;
            }
        }
        [DataMember]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        [Display(Name = "Login", ResourceType = typeof(ModelStrings))]
        public string Login { get; set; }
        [DataMember]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        [Display(Name = "Language", ResourceType = typeof(ModelStrings))]
        public string Language { get; set; }
        [DataMember]
        [Display(Name = "AssignedClients", ResourceType = typeof(ModelStrings))]
        public IDictionary<int, bool> AssignedClients { get; set; }
        [DataMember]
        [Display(Name = "IsApproved", ResourceType = typeof(ModelStrings))]
        public bool IsApproved { get; set; }
        #endregion
    }
}
